<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="http://foo.org"
	version="2.0">

	<xsl:output method="xml" version="1.0" encoding="UTF-8"
		indent="yes" omit-xml-declaration="no" />

	<xsl:variable name="langTypeLookup"
		select="document('mappings.xml')/type-mappings" />

	<xsl:function name="foo:upper-first">
		<xsl:param name="string" />
		<xsl:value-of
			select="concat(upper-case(substring( $string,1,1)) , substring($string,2))" />
	</xsl:function>
	
		<xsl:function name="foo:lower-first">
		<xsl:param name="string" />
		<xsl:value-of
			select="concat(lower-case(substring( $string,1,1)) , substring($string,2))" />
	</xsl:function>

	<!-- identity template -->
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()" />
		</xsl:copy>
	</xsl:template>

	<xsl:template match="//class/@name">
		<xsl:attribute name="{name()}">	
		<xsl:value-of
			select="foo:upper-first(.)" />
		 </xsl:attribute>
	</xsl:template>

	<xsl:template match="//property/@type">


		<xsl:variable name="type-name">
			<xsl:value-of select="substring-after(.,':')" />
		</xsl:variable>

		<xsl:attribute name="{name()}">	
		<xsl:choose>
			<xsl:when test="$langTypeLookup/type/@name = $type-name">
				<xsl:value-of select="$langTypeLookup/type[@name = $type-name]" />
			</xsl:when>
			<xsl:otherwise> 
					<xsl:value-of
			select="foo:upper-first(.)" />			
			</xsl:otherwise>
		</xsl:choose>
		 </xsl:attribute>
	</xsl:template>

	<xsl:template match="//property/@name">
		<xsl:attribute name="{name()}">
		<xsl:value-of
			select="foo:lower-first(.)" />
		 </xsl:attribute>
	</xsl:template>

</xsl:stylesheet>

